﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Web.Http;
using KL.UFrame.Core.Result;
using KL.UFrame.Data.Business;
using KL.UFrame.Data.Entities;

namespace KL.UFrame.Api.ApiControllers
{
    [RoutePrefix("api/Report")]
    public class ReportController : K9ApiBaseController
    {
        private IReportBusiness _business;
        private ITokenManager _tokenManager;

        public ReportController(IReportBusiness business,ITokenManager tokenManager)
        {
            _business = business;
            _tokenManager = tokenManager;
        }

        public async Task<ResultMessage<List<Report>>> Get()
        {
            return new ResultMessage<List<Report>>(await _business.GetAllAsync());
        }

        public ResultMessage Post(int reportId, DateTime start, DateTime end)
        {
            var token = _tokenManager.GetToken();

            var url= "/Report/Export?reportId=" + reportId + "&start=" + start.ToString("yyyy-MM-dd") + "&end=" +
                   end.ToString("yyyy-MM-dd") + "&token=" + token;

            return new ResultMessage(0,url);
        }
    }
}
